package com.qpkj.oms.result;

import com.qpkj.common.annotation.Excel;
import com.qpkj.common.utils.DateUtils;
import com.qpkj.oms.domain.OmsProduct;
import com.qpkj.oms.domain.OmsTask;
import com.qpkj.oms.domain.OmsTaskStep;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.ObjectUtils;
import org.w3c.dom.ls.LSException;

import java.io.Serializable;
import java.util.List;

/**
 * 领料返回数据
 */
@Data
@ToString
public class TaskReceiveResult implements Serializable {
    private static final long serialVersionUID = -2295128391017820350L;
    /**
     * 任务id
     */
    private Long taskId;
    /**
     * 任务步骤ID
     */
    private Long stepId;
    /**
     * 任务发布时间
     */
    private String pushTime;
    /**
     * 物料名称
     */
    private String productNmae;
    /**
     * 生产数量
     */
    @Excel(name = "生产数量")
    private Integer productNum;
    /**
     * 物料颜色
     */
    private String productColour;
    /**
     * 物料规格
     */
    private String productSku;
    /**
     * 计划完成时间
     */
    private String finishDate;
    /**
     * 领料完成时间
     */
    private String completeTime;
    /**
     * 经办人
     */
    private String handleName;
    /**
     * 驳回时间
     */
    private String backTime;
    /**
     * 状态(0待完成；1完成；2驳回)
     */
    private String status;
    /**
     * 状态(1可以驳回；0不可驳回)
     */
    private String canReject;
    /**
     *交付客户
     */
    private String deliver;
    /**
     *交付客户
     */
    private String isBuShu;
    /**
     * 生产所需物料集合
     */
    private List<ReceiveProductResut> resutList;

    public static TaskReceiveResult buildResult(OmsTask task, List<ReceiveProductResut> resutList, OmsTaskStep taskStep) {
        TaskReceiveResult result = new TaskReceiveResult();
        result.setTaskId(task.getTaskId());
        result.setStepId(taskStep.getStepId());
        result.setPushTime(DateUtils.parseDateToStr("yyyy-MM-dd", task.getReleaseTime()));
        result.setFinishDate(DateUtils.parseDateToStr("yyyy-MM-dd", task.getFinishTime()));
        if (!ObjectUtils.isEmpty(taskStep.getStepTime())) {
            result.setCompleteTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", taskStep.getStepTime()));
        }
        result.setHandleName(taskStep.getOperatorName());
        if (!ObjectUtils.isEmpty(taskStep.getRejectTime())) {
            result.setBackTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", taskStep.getRejectTime()));
        }
        result.setStatus(taskStep.getStepStatus());
        result.setResutList(resutList);
        return result;
    }
}
